<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        v-model="pageParam.model.patientName"
        style="width: 200px;"
        placeholder="姓名查询..."
        class="filter-item"
        @keyup.enter.native="handleFilter"
        @input="handleFilter"
      />
      <el-select v-model="pageParam.model.status" placeholder="请选择状态" @change="getListByPage()">
        <el-option label="全部" value="" />
        <el-option label="未审核" value="0" />
        <el-option label="审核完成" value="1" />
      </el-select>
    </div>

    <!-- 表格 -->
    <el-table :data="list" fit highlight-current-row style="width: 100%;" @sort-change="sortChange">
      <el-table-column class="filter-item" type="expand">
        <template slot-scope="{row}">
          <el-form label-position="left" inline class="demo-table-expand">
            <!-- 行数据详情字段 -->
            <el-form-item label="出院描述">
              <span>{{ row.descript }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="patientName" label="病人姓名" />
      <el-table-column prop="nurseName" label="审核护士姓名" />
      <el-table-column prop="doctorName" label="申请医生姓名" />
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status==0">待处理</span>
          <span v-if="scope.row.status==1">已完成</span>
        </template>
      </el-table-column>
      <el-table-column sortable="custom" prop="createTime" label="创建日期" />

      <el-table-column label="操作" fit>
        <template slot-scope="{row,$index}">
          <el-button size="small" v-if="row.status=='0'" type="danger" @click="checkOk(row)">同意出院</el-button>
          <el-button size="small" v-else type="info">已同意</el-button>
        </template>
      </el-table-column>

    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getListByPage"
    />
  </div>
</template>

<script>
import {
  add,
  check,
  getAll
} from '@/api/application/outApply'
// 导入组件  记得声明组件
import Pagination from '@/components/Pagination'

export default {
  components: { // 在这里声明组件
    Pagination
  },
  data() {
    return {
      list: [], // 列表数据
      total: 0,
      listQuery: { // 分页 排序  查询参数
        pageNum: 1,
        pageSize: 5
      },
      pageParam: {
        pageNum: 1,
        pageSize: 5,
        model: {
          patientName: '',
          status: ''
        },
        orderParams: []
      }
    }
  },
  created() {
    this.getListByPage()
  },
  methods: {
    // 根据病人住院编号获取病人信息
    checkOk(id) {
      check(id).then(res => {
        this.$notify({
          title: 'Success',
          message: 'Created Successfully',
          type: 'success',
          duration: 2000
        })
        this.getListByPage()
      })
    },
    sortChange(val) {
      // console.log("排序参数",val)
      const prop = val.prop
      const order = val.order === 'ascending' ? 'asc' : 'desc'
      let orderParam
      orderParam = 'a.create_time' + ' ' + order
      this.pageParam.orderParams = []
      this.pageParam.orderParams.push(orderParam)
      this.getListByPage()
    },
    getListByPage() {
      this.pageParam.pageNum = this.listQuery.pageNum
      this.pageParam.pageSize = this.listQuery.pageSize
      getAll(this.pageParam).then(res => {
        // console.log(res)
        this.list = res.content.list
        this.total = res.content.total
      }).catch(err => {
        console.log(err)
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getListByPage()
    }
  }
}
</script>

<style>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
